﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CNKI.TPI.Web.Search.Model;
using CNKI.TPI.Web.Base;

namespace CNKI.TPI.Web.Search.IBLL
{
    /// <summary>
    /// 检索Service
    /// </summary>
    public interface ISearchService
    {
        /// <summary>
        /// 获得检索条件字段
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>检索字段</returns>
        IList<SYS_CMS_DATABASE_PUBLISH_FIELD> GetSearchFieldList(int dbID);

        /// <summary>
        /// 获得跨库查询条件字段
        /// </summary>
        /// <returns>检索字段</returns>
        IList<DBUSFIELD> GetUnionSearchFieldList();
        /// <summary>
        /// 根据字段类型获得跨库查询条件字段
        /// </summary>
        /// <returns>检索字段</returns>
        /// fieldtype  1 检索 2 排序 ，3 概览
        IList<DBUSFIELD> GetUnionFieldList(FieldType fieldtype);
        /// <summary>
        /// 获得跨库检索查询数据库
        /// </summary>
        /// <param name="classCode">跨库分类编码</param>
        /// <returns>对应的数据库信息列表</returns>
        IList<DBCONFIG> GetUnionDBList(string classCode = null);

        /// <summary>
        /// 获得细览发布字段
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>细览发布字段</returns>
        IList<SYS_CMS_DATABASE_PUBLISH_FIELD> GetDetailFieldList(int dbID);

        /// <summary>
        /// 获得排序发布字段
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>排序发布字段</returns>
        IList<SYS_CMS_DATABASE_PUBLISH_FIELD> GetSortFieldList(int dbID);

        /// <summary>
        /// 单库检索
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <param name="dbName">数据库编码</param>
        /// <param name="searchQuery">查询条件</param>
        /// <param name="selectedCatTypeID">导航分类</param>
        /// <param name="categroyID">导航信息</param>
        /// <param name="strGroup">分组</param>
        /// <param name="strOrder">排序</param>
        /// <param name="pageIndex">显示页数</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="selectField">输出字段</param>
        /// <param name="option">是否进行权限过滤</param>
        /// <param name="enableCache">是否启用缓存</param>
        /// <param name="topicCLSCode">是否进行权限过滤</param>
        /// <param name="topicCLSNodeCode">是否进行权限过滤</param>
        /// <returns>查询结果</returns>
        DataSet SingleSearch(int dbID, string dbName, IList<SearchQuery> searchQuery, int selectedCatTypeID, string categroyID, string strGroup, string strOrder, int pageIndex, int pageSize, string selectField = null, PermissionOption option = PermissionOption.FilteringPermissions, bool enableCache = true, string topicCLSCode = "", string topicCLSNodeCode = "");

        /// <summary>
        /// 单库检索
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <param name="dbName">数据库编码</param>
        /// <param name="searchQuery">查询条件</param>
        /// <param name="selectedCatTypeID">导航分类</param>
        /// <param name="categroyID">导航信息</param>
        /// <param name="strGroup">分组</param>
        /// <param name="strOrder">排序</param>
        /// <param name="pageIndex">显示页数</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="selectField">输出字段</param>
        /// <param name="option">是否进行权限过滤</param>
        /// <param name="enableCache">是否启用缓存</param>
        /// <param name="topicCLSCode">是否进行权限过滤</param>
        /// <param name="topicCLSNodeCode">是否进行权限过滤</param>
        /// <returns>查询结果</returns>
        DataSet SingleSearch(int dbID, string dbName, IList<SearchQuery> searchQuery, int selectedCatTypeID, string categroyID, string strGroup, string strOrder, int pageIndex, int pageSize, out string query, string selectField = null, PermissionOption option = PermissionOption.FilteringPermissions, bool enableCache = true, string topicCLSCode = "", string topicCLSNodeCode = "");

        /// <summary>
        /// 友情链接检索
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>链接结果</returns>
        DataSet JumpInfoSearch(int dbID);

        /// <summary>
        /// 加载细览
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <param name="dbName">数据库编码</param>
        /// <param name="searchQuery">检索条件</param>
        /// <param name="dbInfo">dbInfo</param>
        /// <returns>检索结果</returns>
        DataSet SearchDetail(int dbID, string dbName, IList<SearchQuery> searchQuery, SYS_CMS_DATABASE dbInfo);

        /// <summary>
        /// 加载细览
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <param name="searchQuery">检索条件</param>
        /// <returns>检索结果</returns>
        DataSet SearchDetail(int dbID, IList<SearchQuery> searchQuery);

        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="recordID">记录ID</param>
        /// <param name="dbName">数据库编码</param>
        /// <returns>文件信息列表</returns>
        IList<METADATA_FILE> GetFile(int recordID, string dbName);
         /// <summary>
       /// 获取文件信息
       /// </summary>
       /// <param name="recordID">记录ID</param>
       /// <param name="dbName">数据库编码</param>
       /// <param name="type">数据库类型</param>
       /// <returns></returns>
       IList<METADATA_FILE> GetFile(int recordID, string dbName, MediaType type);
        /// <summary>
        /// 多库检索
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <param name="dbName">数据库编码</param>
        /// <param name="searchQuery">查询条件</param>
        /// <param name="selectedCatTypeID">导航分类</param>
        /// <param name="categroyID">导航明细</param>
        /// <param name="strGroup">分组</param>
        /// <param name="strOrder">排序</param>
        /// <param name="pageIndex">请求页面</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="classCode">classCode</param>
        /// <returns>查询结果</returns>
        DataSet MultiSearch(string dbID, string dbName, IList<SearchQuery> searchQuery, int selectedCatTypeID, string categroyID, string strGroup, string strOrder, int pageIndex, int pageSize, string classCode);

        DataSet MultiSearch(string dbID, string dbName, IList<SearchQuery> searchQuery, int selectedCatTypeID, string categroyID, string strGroup, string strOrder, int pageIndex, int pageSize, string classCode, out string str_query);

        /// <summary>
        /// 获取相似检索数据库
        /// </summary>
        /// <param name="dbCode">数据库编码</param>
        /// <returns>数据库信息</returns>
        DataTable GetSimilarList(string dbCode);

        /// <summary>
        /// 获得首页推送数据库
        /// </summary>
        /// <param name="typename">类型</param>
        /// <returns>数据库猫叔</returns>
        IList<string> GetHomeBase(string typename);

        /// <summary>
        /// 根据ID获取数据库实例
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>数据库信息</returns>
        SYS_CMS_DATABASE GetDataByID(int dbID);

        /// <summary>
        /// 获得跨库检索分类
        /// </summary>
        /// <returns>跨库分类</returns>
        IList<DBCLASS> GetUnionClass();
        /// <summary>
        /// 根据用户ID和时间段获取检索词
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        string GetQueryByUserCode(string userCode);

         /// <summary>
        /// 删除METADATA 记录
        /// </summary>
        /// <param name="sysid"></param>
        /// <param name="dbCode"></param>
        /// <returns></returns>
        bool DelMetaData(int sysid, string dbCode);

        /// <summary>
        /// 更新METADATA 记录
        /// </summary>
        /// <param name="sysid"></param>
        /// <param name="dbCode"></param>
        /// <param name="fieldList"></param>
        /// <returns></returns>
        bool UpdateMetaData(string sysid, string dbCode, Dictionary<string, object> fieldList);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        DataTable GetDataBySql(string sql);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pageIndes"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        DataTable GetDataBySql(string sql, int pageIndes, int pageSize, out int count);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        int ExecuteNonQuery(string sql);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dbCode"></param>
        /// <param name="fieldList"></param>
        /// <returns></returns>
        int InsertMetaData(string dbCode, Dictionary<string, object> fieldList);

          /// <summary>
        /// 获得概览发布字段
        /// </summary>
        /// <param name="dbID"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        IList<SYS_CMS_DATABASE_PUBLISH_FIELD> GetOverviewFieldList(int dbID, PermissionOption option = PermissionOption.FilteringPermissions);
         /// <summary>
        /// 去除子节点
        /// </summary>
        /// <param name="dbCode"></param>
        /// <returns></returns>
        string processCategoryID(string dbCode);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dbCode"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        Dictionary<string, string> GetFieldMatchTypeList(string dbCode, string fieldName);
    }

}
